#include<fstream>
#include<cstring>
#include"FileReader.h"
#include<iostream>


using namespace std;

FileReader::FileReader(const char* str)
{
	linepos = 0;
	bufsize = 0;
	strcpy(filename,str);
	FileReader::openline();
}

FileReader::~FileReader()
{
	FileReader::closeline();
}

bool FileReader::m_openFile()
{
	ifstream myfile(filename,ios_base::in);
	if(myfile)
		return 1;
	else
		return 0;
	
}

void FileReader::openline()
{
	myfile.open(filename,ios_base::in);
}


char FileReader::m_getNextChar()
{
	if(!(linepos<=bufsize))
	{
		if(myfile.getline(lineBuf,BUFLEN))
		{
			bufsize = myfile.gcount();//strlen(lineBuf);
			lineBuf[bufsize++] ='\n';
			linepos = 0;
			return lineBuf[linepos++];
		}
		else
		{
			return EOF;
		}
	}
	else return lineBuf[linepos++];
}









void FileReader::closeline()
{
	myfile.close();
}


char FileReader::m_getPreChar()
{
	--linepos;
	return lineBuf[linepos++];
}




char FileReader::nextchar_()
{
	return myfile.get();
}



void FileReader::prechar_()
{
	 myfile.seekg(-1,ios::cur);
	 return ;
}